<?php 
class ControllerCommonHeader extends Controller {
	protected function index() {
		$this->data['title'] = $this->document->getTitle(); 
		
		if (isset($this->request->server['HTTPS']) && (($this->request->server['HTTPS'] == 'on') || ($this->request->server['HTTPS'] == '1'))) {
			$this->data['base'] = HTTPS_SERVER;
		} else {
			$this->data['base'] = HTTP_SERVER;
		}
		
		$this->data['description'] = $this->document->getDescription();
		$this->data['keywords'] = $this->document->getKeywords();
		$this->data['links'] = $this->document->getLinks();
		$this->data['styles'] = $this->document->getStyles();
		$this->data['scripts'] = $this->document->getScripts();
		
		if (!$this->admin->isLogged() || !isset($this->request->get['token']) || !isset($this->session->data['token']) || ($this->request->get['token'] != $this->session->data['token'])) {
			$this->data['logged'] = '';
			
			$this->data['home'] = $this->url->link('common/login', '', 'SSL');
		} else {
			$this->data['logged'] = sprintf('用户：%s', $this->admin->getUserName());	
			$this->data['logout'] = $this->getTokenUrl('common/logout');
			$this->data['user'] = $this->getTokenUrl('management/user');
			$this->data['page'] = $this->getTokenUrl('management/page');
		}
		
		$this->template = 'common/header.tpl';
		
		$this->render();
	}
	
	private function getTokenUrl($route){
		$token_url = $this->url->link($route, 'token='.$this->session->data['token'],'SSL');
		return $token_url;
	}
}
?>